package com.ssm.zhihu_ssm.controller;

import com.ssm.zhihu_ssm.entity.User;
import com.ssm.zhihu_ssm.entity.UserMessage;
import com.ssm.zhihu_ssm.service.UserService;
import com.ssm.zhihu_ssm.util.ReturnMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping("/login")//登录
    @ResponseBody
    public Map<String, Object> index(String phone,String password){

        String user = userService.loginUser(phone,password);
        Map<String, Object> map = ReturnMap.Returncode(user);
        return map;
    }

    @RequestMapping("/apply")//注册
    @ResponseBody
    public Map<String, Object> apply(String phone,String password){
        Boolean apply = userService.applyUser(phone,password);

        Map<String, Object> map = ReturnMap.ReturnMapS(apply);
        return map;
    }

    @RequestMapping("/getAllUser")//得到所有用户
    @ResponseBody
    private Map<String, Object> getAllUser() {

        List<User> users =  userService.getAllUser();
        Map<String, Object> map = ReturnMap.ReturnMapS(users);
        return map;

    }

}
